package com.prj.ufdm.webflux.config;

import org.springframework.beans.factory.FactoryBean;
import org.springframework.context.ApplicationContext;

import com.prj.ufdm.webflux.proxy.DynamicDeviceDefaultHandlerProxy;

/**
 * DESC: FactoryBean处理类
 * @author Administrator
 * @param <T>
 */
public class HandlerFactoryBean<T> implements FactoryBean<T> {
	
//    private Class<T> interfaceClass;
    private String className;
    private ApplicationContext context;
    
//	public HandlerInterfaceFactoryBean(String className, ApplicationContext context) {
//		super();
//		this.className = className;
//		this.context = context;
//	}
    
    @Override
    public T getObject() throws Exception {
    	
    	this.className = "com.prj.ufdm.webflux.bpo.DeviceHandler";
    	
    	System.out.println("\n 执行 HandlerInterfaceFactoryBean getObject 方法");
    	
    	System.out.println("\n HandlerInterfaceFactoryBean getObject : " + this.className);
    	
        Object object = DynamicDeviceDefaultHandlerProxy.newMapperProxy(this.className,this.context);
        
        return (T) object;
    }

    @Override
    public Class<?> getObjectType() {
    	
    	this.className = "com.prj.ufdm.webflux.bpo.DeviceHandler";
    	
//    	System.out.println("\n 执行 HandlerInterfaceFactoryBean getObjectType 方法");
    	
//    	System.out.println("\n HandlerInterfaceFactoryBean getObjectType : " + this.className);
    	
        try {
			return Class.forName(this.className);
		} catch (ClassNotFoundException e) {
			e.printStackTrace();
		}
        return null;
    }

    @Override
    public boolean isSingleton() {
        return true;
    }

	public String getClassName() {
		return className;
	}

	public void setClassName(String className) {
		this.className = className;
	}

	public ApplicationContext getContext() {
		return context;
	}

	public void setContext(ApplicationContext context) {
		this.context = context;
	}

}
